Currently, xm & xend allow an XAUTHORITY to be specified in the config
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 31 Mar 2006 12:51:19 +0000 (13:51 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 31 Mar 2006 12:51:19 +0000 (13:51 +0100)
file.  If that is not specified, then xm will pass the XAUTHORITY
environment variable back to xend instead.  This is not sufficient,
since it is possible that XAUTHORITY is not set at all.  This doesn't
cause a problem for most X apps, because xlib will use the fall-back of
$HOME/.Xauthority.  But the viewer is started from xend, which almost
certainly doesn't have a reasonable HOME variable.

We fix this by always passing some value for
XAUTHORITY.  In order of preference, that value is:
1.  Use the value from the config file, if specified.
2.  Use the value from the XAUTHORITY env variable, if set.
3.  Use $HOME/.Xauthority, if HOME is set.
4.  Look up the user's home directory via getpwuid, and append
"/.Xauthority"

Signed-off-by: Charles Coffing <ccoffing@novell.com>
tools/python/xen/xm/create.py

index adfd6f1f420d94651721ce04ad5fb3787f3a2511..2933af5e4fe0b7188609753591330819aeae6ec1 100644 (file)
@@ -864,7 +864,14 @@ def parseCommandLine(argv):
         gopts.vals.display = os.getenv("DISPLAY")
 
     if not gopts.vals.xauthority:
-        gopts.vals.xauthority = os.getenv("XAUTHORITY")
+        xauth = os.getenv("XAUTHORITY")
+        if not xauth:
+            home = os.getenv("HOME")
+            if not home:
+                import posix, pwd
+                home = pwd.getpwuid(posix.getuid())[5]
+            xauth = home + "/.Xauthority"
+        gopts.vals.xauthority = xauth
 
     # Process remaining args as config variables.
     for arg in args: